home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_200 / 248_01 / replace.c < prev    next >
Text File  |  1989-08-16  |  3KB  |  117 lines

  1. /*
  2. **    name:        replace.c
  3. **    purpose:    Generate possible replacements for misspelled words
  4. **    status:        Copyright (c) 1988 - 1988
  5. **    author:        Roberto Artigas Jr - All rights reserved
  6. **    usage:        Non-commercial use, user supported software
  7. **    syntax:        replace badword
  8. **    samples:    replace A        (test)
  9. **            replace animel        (test)
  10. */
  11. #define    maindef
  12.  
  13. #include    <stdio.h>
  14. #include    "dopt.h"
  15. #include    "dstruct.h"
  16. #include    "ddef.h"
  17. #include    "dsfx2.h"
  18.  
  19. int        matches();
  20. char        *translate_case();
  21. int        mopen();
  22. void        mclose();
  23. char        *nxtmword();
  24.  
  25. /*
  26. **    name:        trymatch
  27. **    purpose:    Try matching with normal algorithms first
  28. **            then by applying the suffix table to the word
  29. */
  30. int    trymatch(word,pattern,display)
  31. char    *word;
  32. char    *pattern;
  33. char    *display;
  34. {
  35.     static    int    matched, i;
  36.     static    char    hold[50];
  37.  
  38.     strcpy(hold,word);
  39.     matched = matches(word,pattern);
  40.     if (matched) {
  41.         fprintf(stdout,"%2d %s\n",matched,display);
  42.         return(matched);
  43.     }
  44. /*
  45. **    This technique is VERY time consuming. Adding a suffix to
  46. **    the word and then going to the match algorithm again just
  47. **    increases the time factor to an undesirable level.
  48. **    THIS ROUTINE COMMENTED OUT -
  49. */
  50. /* **********
  51.     for (i=0; i < NSUFFIX2; i++) {
  52.         strcpy(word,hold); strcat(word,sfx2[i]);
  53.         matched = matches(word,pattern);
  54.         if (matched) {
  55.             fprintf(stdout,"%2d %s\n",matched,display);
  56.             return(matched);
  57.         }
  58.     }
  59. ********** */
  60.     return(0);
  61. }
  62.  
  63. /*
  64. **    purpose:    Begin program here
  65. */
  66. int    main(argc,argv)
  67. int    argc;
  68. char    *argv[];
  69. {
  70.     FILE    *textin;
  71.     char    *word, *dummy;
  72.     char    cword[50];
  73.     char    dword[50];
  74.     char    eword[50];
  75.     char    sword[50];
  76.     int    length = 0;
  77.     int    matched = 0;
  78.     int    count = 0;
  79.  
  80. fprintf(stderr,"REPLACE Dictionary Utility for MicroSPELL v1.00\n");
  81.     fprintf(stderr,"[Display posible words begin]\n");
  82.     strcpy(sword,argv[1]); translate_case(sword);
  83. /*
  84. **    This area processes the common word list (common.txt)
  85. */
  86.     fprintf(stderr,"[Common search]\n");
  87.     textin = fopen(comlist,"r");
  88.     if (!textin) {
  89.         fprintf(stderr,"Can't open input file %s\n",comlist);
  90.         return(1);
  91.     }
  92.     while (dummy = fgets(eword,sizeof(eword),textin)) {
  93.         if (*eword > *sword) break;
  94.         length = strlen(eword);
  95.         if (eword[length-1] == '\n') eword[length-1] = '\0';
  96.         strcpy(dword,eword); strcpy(cword,argv[1]);
  97.         matched = trymatch(cword,dword,eword);
  98.         if (matched) count++;
  99.     }
  100.     fclose(textin);
  101. /*
  102. **    This area processes the dictionary (dict.dct)
  103. */
  104.     fprintf(stderr,"[Dictionary search]\n");
  105.     if (!mopen()) return(1);
  106.     while ((word = nxtmword()) != hivalue) {
  107.         if (*word > *sword) break;
  108.         strcpy(dword,word); strcpy(cword,argv[1]);
  109.         matched = trymatch(cword,dword,word);
  110.         if (matched) count++;
  111.     }
  112.     mclose();
  113.     fprintf(stderr,"[%d posible words matched]\n",count);
  114.     fprintf(stderr,"[Display posible words ended]\n");
  115.     return(0);
  116. }
  117.